{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import necessary modules\n",
    "# uncomment to get plots displayed in notebook\n",
    "%matplotlib inline\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from classy import Class"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "font = {'size'   : 20, 'family':'STIXGeneral'}\n",
    "axislabelfontsize='large'\n",
    "matplotlib.rc('font', **font)\n",
    "matplotlib.mathtext.rcParams['legend.fontsize']='medium'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Lambda CDM\n",
    "LCDM = Class()\n",
    "LCDM.set({'Omega_cdm':0.25,'Omega_b':0.05})\n",
    "LCDM.compute()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Einstein-de Sitter\n",
    "CDM = Class()\n",
    "CDM.set({'Omega_cdm':0.95,'Omega_b':0.05})\n",
    "CDM.compute()\n",
    "\n",
    "# Just to cross-check that Omega_Lambda is negligible \n",
    "# (but not exactly zero because we neglected radiation)\n",
    "derived = CDM.get_current_derived_parameters(['Omega0_lambda'])\n",
    "print (derived)\n",
    "print (\"Omega_Lambda =\",derived['Omega0_lambda'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Get background quantities and recover their names:\n",
    "baLCDM = LCDM.get_background()\n",
    "baCDM = CDM.get_background()\n",
    "baCDM.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Get H_0 in order to plot the distances in this unit\n",
    "fLCDM = LCDM.Hubble(0)\n",
    "fCDM = CDM.Hubble(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "namelist = ['lum. dist.','comov. dist.','ang.diam.dist.']\n",
    "colours = ['b','g','r']\n",
    "for name in namelist:\n",
    "    idx = namelist.index(name)\n",
    "    plt.loglog(baLCDM['z'],fLCDM*baLCDM[name],colours[idx]+'-')\n",
    "plt.legend(namelist,loc='upper left')\n",
    "for name in namelist:\n",
    "    idx = namelist.index(name)\n",
    "    plt.loglog(baCDM['z'],fCDM*baCDM[name],colours[idx]+'--')\n",
    "plt.xlim([0.07, 10])\n",
    "plt.ylim([0.08, 20])\n",
    "\n",
    "plt.xlabel(r\"$z$\")\n",
    "plt.ylabel(r\"$\\mathrm{Distance}\\times H_0$\")\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.savefig('distances.pdf')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
